﻿<UserControl
    x:Class="AmazonS3PublishPlugin.StandardUI"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:app="clr-namespace:AmazonS3PublishPlugin"
    mc:Ignorable="d" 
    Tag="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Grid, AncestorLevel=3}}"
    Loaded="OnLoaded">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Assets/Styles.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <app:BooleanInverter x:Key="BooleanInverter" />
        </ResourceDictionary>
    </UserControl.Resources>
    
    <UserControl.CommandBindings>
        <CommandBinding Command="{x:Static app:Commands.ListBuckets}" Executed="ListBuckets_Executed" CanExecute="ListBuckets_CanExecute" />
    </UserControl.CommandBindings>

    <UserControl.ContextMenu>
        <ContextMenu>
            <MenuItem Header="Capture UI" Click="CaptureUI_Click" />
        </ContextMenu>
    </UserControl.ContextMenu>

    <Grid DataContext="{Binding Data}">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        
        <Label Content="Access Key ID" />
        <TextBox Style="{StaticResource TextBoxStyle}"
                 Text="{Binding AccessKeyId, UpdateSourceTrigger=PropertyChanged}"
                 Grid.Column="1" />
        
        <Label Content="Secret Access Key" Grid.Row="1" />
        <PasswordBox Name="SecretAccessKey"
                     Grid.Column="1" Grid.Row="1"
                     PasswordChanged="SecretAccessKey_PasswordChanged" />
        <CheckBox Style="{StaticResource CheckBoxStyle}"
                  IsChecked="{Binding SaveSecretAccessKey}"
                  Content="Remember Secret Access Key"
                  Grid.Column="1" Grid.Row="2" />
        <TextBlock Style="{StaticResource HyperlinkTextBlockStyle}"
                   Grid.ColumnSpan="2" Grid.Row="3">
            <Hyperlink NavigateUri="http://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key"
                       RequestNavigate="Hyperlink_RequestNavigate">Security Credentials</Hyperlink>
        </TextBlock>
        
        <Label Content="Bucket" Grid.Row="4" />
        <Grid Grid.Column="1" Grid.Row="4">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <ComboBox Name="BucketList" Style="{StaticResource ComboBoxStyle}"
                      ItemsSource="{Binding Buckets}"
                      DisplayMemberPath="BucketName" IsEditable="True"
                      Text="{Binding BucketName, UpdateSourceTrigger=PropertyChanged}" />
            <Button Command="{x:Static app:Commands.ListBuckets}"
                    VerticalAlignment="Center"
                    Margin="{DynamicResource DefaultLeftTopMargin}"
                    Grid.Column="1">
                <StackPanel Orientation="Horizontal" Margin="4,0">
                    <Ellipse Style="{StaticResource AuthenticationStyle}" Width="14" Height="14" Fill="Gray" />
                    <TextBlock Text="List" Margin="4,0,0,0" />
                </StackPanel>
            </Button>
        </Grid>
        
        <Label Content="Folder" Grid.Row="5" />
        <TextBox Style="{StaticResource ValidationTextBoxStyle}"
                 Text="{Binding FolderName, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
                 IsEnabled="{Binding UseJobOutputFolder, Converter={StaticResource BooleanInverter}}"
                 Grid.Column="1" Grid.Row="5">
        </TextBox>

        <StackPanel Grid.Column="1" Grid.Row="6">
            <CheckBox Style="{StaticResource CheckBoxStyle}"
                      IsChecked="{Binding UseJobOutputFolder}"
                      Content="Use job output folder" />
            <CheckBox Style="{StaticResource CheckBoxStyle}"
                      IsChecked="{Binding UseReducedRedundancyStorage}"
                      Content="Use Reduced Redundancy Storage" />
            <CheckBox Style="{StaticResource CheckBoxStyle}"
                      IsChecked="{Binding MakePublic}"
                      Content="Make everything public" />
            <CheckBox Style="{StaticResource CheckBoxStyle}"
                      IsChecked="{Binding UseHttps}"
                      Content="Use HTTPS" />
            <CheckBox Style="{StaticResource CheckBoxStyle}"
                      IsChecked="{Binding OpenInBrowser}"
                      Content="Open in browser" />
        </StackPanel>
    </Grid>
</UserControl>
